package no.sachmuld.aspectjattach;

import org.apache.log4j.Logger;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;

public class LoggingClassFileTransformer implements ClassFileTransformer {

    private static Logger logger = Logger.getLogger(LoggingClassFileTransformer.class);

    private ClassFileTransformer target;

    public LoggingClassFileTransformer(ClassFileTransformer target) {
        this.target = target;
    }

    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

        logger.debug("Transforming : " + className);
        return target.transform(loader, className,  classBeingRedefined, protectionDomain, classfileBuffer);

    }
}
